package com.cos.blog.core.service;


import com.cos.blog.core.dao.IBaseDao;

import java.util.List;

public abstract class BaseServiceImpl<T> implements IBaseService<T> {

    protected abstract IBaseDao<T> getBaseDao(); // 这里只是申明了,需要实例化

    // 业务层只需调用dao层
    @Override
    public boolean save(T t) throws Exception {
        return getBaseDao().insert(t) > 0;
    }

    @Override
    public boolean update(T t) throws Exception {
        return getBaseDao().updateById(t) > 0;
    }

    @Override
    public boolean remove(Integer id) throws Exception {
        return getBaseDao().deleteById(id) > 0;
    }

    @Override
    public T byId(Integer id) throws Exception {
        return getBaseDao().selectById(id);
    }

    @Override
    public List<T> list() throws Exception {
        return getBaseDao().selectList();
    }

    @Override
    public boolean batchRemove(List<Integer> ids) throws Exception {
        return getBaseDao().batchRemove(ids) > 0;
    }
}
